package com.sunni.repository;

import com.sunni.entity.Account;
import org.apache.ibatis.io.ResolverUtil;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.InputStream;


public class AccountMapper {

    @Test
    public void test01(){
// 1. 读取mybatis核心文件
        InputStream resourceAsStream =
                ResolverUtil.Test.class.getClassLoader().getResourceAsStream("config.xml");

// 2.创建SqlSessionFactoryBuilder();
        SqlSessionFactoryBuilder sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder();

//  3.拿到sqlSessionFactory
        SqlSessionFactory sqlSessionFactory = sqlSessionFactoryBuilder.build(resourceAsStream);

//  4.开启SqlSession对话
        SqlSession sqlSession = sqlSessionFactory.openSession();

// 5.执行sql会话，找AccountMapper.xml 实现类
        String statement = "com.sunni.repository.AccountMapper.insert";
        int result = sqlSession.insert(statement, new Account("高音哥", "123", 29));

// 6.提交sql会话
        sqlSession.commit();

//  7.关闭sql会话
        sqlSession.close();
    }

    @Test
    public void test02(){

    }


}
